package com.worldvision.main.page.member;

import java.util.HashMap;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import com.worldvision.main.util.Report;
import com.worldvision.main.util.UTIL;

public class MyNextPaymentPage extends abstractLoginPage
{
	static HashMap locator = new HashMap<String,String>()
	{
		{
			put("Period","nQty[]");
			put("Amount","nItemCost[]");
			put("Total","nTotal");
			put("GrandTotal","GTotal");
			put("Update","submitbut");
			put("Submit","submit");
			put("ConfirmGift","submitbut");
			put("RowTotal1","//tr[3]/td[3]");
			put("RowTotal2","//tr[5]/td[3]");
			put("GrandTotalPayment","//div[2]/table/tbody/tr[2]/td/table/tbody/tr[5]/td[2]");
		}
	
	};
	
	public MyNextPaymentPage(WebDriver driver) {
		
		this.driver = driver;
	}
	
	public void addSponser(String period,String amt)
	{
		
		UTIL.selectElement(driver,By.id(locator.get("Period").toString()),period);
//		driver.findElement(By.id(locator.get("Amount").toString())).sendKeys(amt);
		checkTotals(amt,amt,amt);
		driver.findElement(By.id(locator.get("Update").toString())).click();
		UTIL.waitForText(driver,"Gifts You Have Selected");
		driver.findElement(By.name(locator.get("ConfirmGift").toString())).click();
		UTIL.waitForText(driver,"Gifts You Have Selected");
		checkPaymentPage(amt,amt);
		
		
	}
	public void submitPayment()
	{
		
		driver.findElement(By.id(locator.get("Update").toString())).click();
		UTIL.waitForText(driver,"Gifts You Have Selected");
		driver.findElement(By.name(locator.get("ConfirmGift").toString())).click();
		UTIL.waitForText(driver,"Gifts You Have Selected");
		
		
		
	}
	
	
	private void checkPaymentPage(String amt,String grandAmt) {
		
		if(driver.findElement(By.xpath(locator.get("RowTotal").toString())).getText().contains(amt))
		{
			Report.passMSG("RowTotal as expected");
		}
		else
		{
			Report.failMSG("RowTotal is not as expected");
		}
		
		if(driver.findElement(By.xpath(locator.get("GrandTotalPayment").toString())).getText().contains(amt))
		{
			Report.passMSG("Grand Amount in payment page as expected");
		}
		else
			Report.failMSG("Grand Amount in payment page is not expected");
		
		
	}
	public void checkRowPaymentPage(int row,String rowTotal,String grandTotal) {
		
		if(driver.findElement(By.xpath(locator.get("RowTotal"+row).toString())).getText().contains(rowTotal))
		{
			Report.passMSG("RowTotal as expected");
		}
		else
		{
			Report.failMSG("RowTotal is not as expected");
		}
		
		if(driver.findElement(By.xpath(locator.get("GrandTotalPayment").toString())).getText().contains(grandTotal))
		{
			Report.passMSG("Grand Amount in payment page as expected");
		}
		else
			Report.failMSG("Grand Amount in payment page is not expected");
		
		
	}

	public void checkTotals(String amt,String semiAmt,String grandAmt)
	{
		if(driver.findElement(By.id(locator.get("Amount").toString())).getText().contains(amt))
		{
			Report.passMSG("Monthly Amount as expected");
		}
		else
		{
			Report.failMSG("Monthly Amount is not as expected");
		}
		if(driver.findElement(By.id(locator.get("Total").toString())).getText().contains(semiAmt))
		{
			Report.passMSG("Total as expected");
		}
		else
		{
			Report.failMSG("Total is not as expected");
		}
		if(driver.findElement(By.id(locator.get("GrandTotal").toString())).getText().contains(grandAmt))
		{
			Report.passMSG("Grand Amount as expected");
		}
		else
			Report.failMSG("Grand Amount as not expected");
		
	}

	public void checkSponserRowAmount(int i, String amt) 
	{
		if(driver.findElement(By.xpath("(//input[@id='"+locator.get("Amount").toString()+"'])["+(i)+"]")).getText().contains(amt))
		{
			Report.passMSG("Monthly Amount as expected");
		}
		else
		{
			Report.failMSG("Monthly Amount is not as expected");
		}
		
	}

	public void addPayRow(int i, String period) {
		// TODO Auto-generated method stub
		UTIL.selectElement(driver,By.xpath("(//*[@id='"+locator.get("Period").toString()+"'])["+(i)+"]"),period);
	}

	public void checkSponserTotals(String semiAmt, String grandAmt) {
		// TODO Auto-generated method stub
		if(driver.findElement(By.id(locator.get("Total").toString())).getText().contains(semiAmt))
		{
			Report.passMSG("Total as expected");
		}
		else
		{
			Report.failMSG("Total is not as expected");
		}
		if(driver.findElement(By.id(locator.get("GrandTotal").toString())).getText().contains(grandAmt))
		{
			Report.passMSG("Grand Amount as expected");
		}
		else
			Report.failMSG("Grand Amount as not expected");
	}
	
	
}
